﻿Partial Public Class LogInfoView_Grid
    Inherits Mysoft.Map.Application.Security.AppPage

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then
            'Dim filter As String
            'filter = Request.QueryString("filter")
            'If filter <> "" Then
            '    AppGrid.Filter = filter.ToString()
            'End If

            Dim CustomerFilter As String = GetCustomerFilter()
            If CustomerFilter <> "" Then
                appGrid.CustomFilter = CustomerFilter
            End If
        End If
    End Sub

    Private Function GetCustomerFilter() As String
        Dim filter As String = ""
        Dim strBeginDate As String = Request.QueryString("BeginDate")
        Dim strEndDate As String = Request.QueryString("EndDate")

        If strBeginDate <> "" AndAlso strEndDate <> "" AndAlso IsDate(strBeginDate) AndAlso IsDate(strEndDate) Then
            Dim beginDate As DateTime = Convert.ToDateTime(strBeginDate)
            Dim endDate As DateTime = Convert.ToDateTime(strEndDate)

            Dim filed As String = GetFieldsName()
            If filed = "" Then Return ""

            filter = filed & " >= '" + beginDate.ToString("yyyy-MM-dd HH:mm:ss") + "' and " & filed & "<'" & endDate.AddDays(1.0).ToString("yyyy-MM-dd HH:mm:ss") & "'"
        End If

        Return filter
    End Function


    Private Function GetFieldsName() As String
        Dim fieldsName As String = ""

        Select Case Request.QueryString("xml")
            Case "/LMS/LogPageExceptionDetail_Grid.xml"
                fieldsName = "Lms_ERP_ExDetailInfo.Date"
                Exit Select
            Case "/LMS/LogPageRequestInfo_Grid.xml"
                fieldsName = "Lms_IIS_PageRequestInfo.FullDate"
                Exit Select
            Case "/LMS/LogPageRequestFailedInfo_Grid.xml"
                fieldsName = "Lms_IIS_PageRequestFailedInfo.FullDate"
                Exit Select
            Case "/LMS/LogWin_Event_Grid.xml"
                fieldsName = "Lms_Win_EventLog.FullDate"
                Exit Select
        End Select

        Return fieldsName
    End Function

End Class